<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Clojure documentation browser</title><style>
.library
{
  padding: 0.5em 0 0 0 
}
.all-libs-toggle,.library-contents-toggle
{
 font-size: small;
}
.all-libs-toggle a,.library-contents-toggle a
{
 color: white
}
.library-member-doc-whitespace
{
 white-space: pre
}
.library-member-source-toggle
{
  font-size: small;
  margin-top: 0.5em
}
.library-member-source
{
  display: none;
  border-left: solid lightblue 
}
.library-member-docs
{
  font-family:monospace
}
.library-member-arglists
{
  font-family: monospace
}
.library-member-type
{
  font-weight: bold; 
  font-size: small;
  font-style: italic;
  color: darkred
}
.lib-links
{
  margin: 0 0 1em 0
}

.lib-link-header
{
  color: white;
  background: darkgreen;
  width: 100%
}

.library-name 
{ 
  color: white;
  background: darkblue;
  width: 100%
}

.missing-library
{
  color: darkred; 
  margin: 0 0 1em 0 
}

.library-members
{
  list-style: none
}

.library-member-name
{
  font-weight: bold;
  font-size: 105%
}</style><script language="JavaScript" type="text/javascript"> // <![CDATA[

function getElem(id)
{
  if( document.getElementById )
  {
    return document.getElementById( id )
  }
  else if ( document.all )
  {
    return eval( 'document.all.' + id )
  }
  else
    return false;
}

function setDisplayStyle(id,displayStyle)
{
  var elem = getElem (id)
  if (elem)
  {
    elem.style.display = displayStyle
  }

}

function setLinkToggleText (id, text)
{
 var elem = getElem (id)
 if (elem)
 {
   elem.innerHTML = text
 }
}

function collapse(id)
{
  setDisplayStyle (id, 'none')
}

function expand (id)
{
  setDisplayStyle (id, 'block')
}

function toggleSource( id )
{
  toggle(id, 'linkto-' + id, 'Hide Source', 'Show Source')
}

function toggle(targetid, linkid, textWhenOpen, textWhenClosed)
{
  var elem = getElem (targetid)
  var link = getElem (linkid)

  if (elem && link)
  {
    var isOpen = false
    if (elem.style.display == '')
    {
      isOpen = link.innerHTML == textWhenOpen
    }
    else if( elem.style.display == 'block' )
    {
      isOpen = true
    }
    
    if (isOpen)
    {
      elem.style.display = 'none'
      link.innerHTML = textWhenClosed
    }
    else
    {
      elem.style.display = 'block'
      link.innerHTML = textWhenOpen
    }
  }
}

      //]]>
</script><script language="JavaScript" type="text/javascript">// <![CDATA[!
function expandAllNamespaces()
{
expand(&apos;library-contents-interface&apos;);
setLinkToggleText(&apos;library-contents-toggle-interface&apos;, &apos;-&apos;);

}function collapseAllNamespaces()
{
collapse(&apos;library-contents-interface&apos;);
setLinkToggleText(&apos;library-contents-toggle-interface&apos;, &apos;+&apos;);

}
// ]]></script></head><body><div class="lib-links"><div class="lib-link-header">Namespaces<span class="all-libs-toggle"> [ <a href="javascript:expandAllNamespaces()">Expand All</a> ] [ <a href="javascript:collapseAllNamespaces()">Collapse All</a> ]</span></div><a class="lib-link" href="#library-interface">interface</a></div><div class="library"><a name="library-interface"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-interface" href="javascript:toggle(&apos;library-contents-interface&apos;, &apos;library-contents-toggle-interface&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>interface</div><div class="library-contents" id="library-contents-interface"><div class="library-member-links"><a class="lib-member-link" href="#member-interface-find-data">find-data</a> <a class="lib-member-link" href="#member-interface-fliplr">fliplr</a> <a class="lib-member-link" href="#member-interface-get-col-names">get-col-names</a> <a class="lib-member-link" href="#member-interface-get-field-lengths">get-field-lengths</a> <a class="lib-member-link" href="#member-interface-get-fields">get-fields</a> <a class="lib-member-link" href="#member-interface-get-magic">get-magic</a> <a class="lib-member-link" href="#member-interface-get-num-fields">get-num-fields</a> <a class="lib-member-link" href="#member-interface-get-offset">get-offset</a> <a class="lib-member-link" href="#member-interface-get-records">get-records</a> <a class="lib-member-link" href="#member-interface-interface">interface</a> <a class="lib-member-link" href="#member-interface-records-to-array">records-to-array</a> <a class="lib-member-link" href="#member-interface-table">table</a></div><ol class="library-members"><li class="library-member"><a name="member-interface-find-data"/><dl class="library-member-table"><dt class="library-member-name">find-data</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([sstring column list])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Finds specified data</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-find-data&apos;)" id="linkto-membersource-interface-find-data">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-find-data"><pre>(defn find-data
  &quot;Finds specified data&quot; 
  [sstring column list] 
  (filter #(= ((keyword column) %) sstring) list))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-fliplr"/><dl class="library-member-table"><dt class="library-member-name">fliplr</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([arr])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Flips an array horizontally</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-fliplr&apos;)" id="linkto-membersource-interface-fliplr">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-fliplr"><pre>(defn fliplr
  &quot;Flips an array horizontally&quot;
  [arr]
  arr
)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-get-col-names"/><dl class="library-member-table"><dt class="library-member-name">get-col-names</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([db])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns a vector containing column names in CAPS LOCK (FOR CRUISE CONTROL)</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-get-col-names&apos;)" id="linkto-membersource-interface-get-col-names">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-get-col-names"><pre>(defn get-col-names
	&quot;Returns a vector containing column names in CAPS LOCK (FOR CRUISE CONTROL)&quot;
	[db]
	(vec (for [[coln _] (get db :fields)] (.toUpperCase coln))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-get-field-lengths"/><dl class="library-member-table"><dt class="library-member-name">get-field-lengths</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([db])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns a vector containing field lengths</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-get-field-lengths&apos;)" id="linkto-membersource-interface-get-field-lengths">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-get-field-lengths"><pre>(defn get-field-lengths
	&quot;Returns a vector containing field lengths&quot;
	[db]
	(vec (for [[_ len] (get db :fields)] len)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-get-fields"/><dl class="library-member-table"><dt class="library-member-name">get-fields</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([db])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns fields from a database</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-get-fields&apos;)" id="linkto-membersource-interface-get-fields">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-get-fields"><pre>(defn get-fields
    &quot;Returns fields from a database&quot;
    [db]
    (get db :fields))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-get-magic"/><dl class="library-member-table"><dt class="library-member-name">get-magic</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([db])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns magic number from a database</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-get-magic&apos;)" id="linkto-membersource-interface-get-magic">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-get-magic"><pre>(defn get-magic
    &quot;Returns magic number from a database&quot;
    [db]
    (get db :magic))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-get-num-fields"/><dl class="library-member-table"><dt class="library-member-name">get-num-fields</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([db])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns number of fields from a database</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-get-num-fields&apos;)" id="linkto-membersource-interface-get-num-fields">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-get-num-fields"><pre>(defn get-num-fields
    &quot;Returns number of fields from a database&quot;
    [db]
    (get db :num-fields))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-get-offset"/><dl class="library-member-table"><dt class="library-member-name">get-offset</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([db])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns offset from a database</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-get-offset&apos;)" id="linkto-membersource-interface-get-offset">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-get-offset"><pre>(defn get-offset
    &quot;Returns offset from a database&quot;
    [db]
    (get db :offset))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-get-records"/><dl class="library-member-table"><dt class="library-member-name">get-records</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([db])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns records from a database</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-get-records&apos;)" id="linkto-membersource-interface-get-records">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-get-records"><pre>(defn get-records 
    &quot;Returns records from a database&quot;
    [db]
    (get db :records))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-interface"/><dl class="library-member-table"><dt class="library-member-name">interface</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([title])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Displays the interface that will be used in the urlybird project</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-interface&apos;)" id="linkto-membersource-interface-interface">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-interface"><pre>(defn interface
  &quot;Displays the interface that will be used in the urlybird project&quot;
  [title]
  (let [filename     &quot;db-1x2 - copia.db&quot;;&quot;db-1x2.db&quot;
        testfilename &quot;db-1x2 - copia.db&quot;
        database     (read-bin-file filename)
        
        datamatrix   (agent (records-to-array (get-records database)))
        
        windowSX     800
        windowSY     600
        labelH       25
        btnSX        150
        btnSY        30
        tableSX      (- windowSX (+ 30 btnSX))
        tableSY      (- windowSY labelH)
        
        frame       (JFrame. title)
        hPanel      (JPanel. )
        fPanel      (JPanel. )
        bPanel      (JPanel. )
        abPanel     (JPanel. )
        
        btnShowall  (JButton. &quot;Show All&quot;)
        btnAdd      (JButton. &quot;Add new row&quot;)
        btnUpdate   (JButton. &quot;Update&quot;)
        btnDelete   (JButton. &quot;Delete&quot;)
        btnFind     (JButton. &quot;Find&quot;)
        
        searchField (JTextField. )
        searchBox   (JComboBox. (to-array (get-col-names database)))
        
        label       (JLabel. &quot;Something&quot;)
        
        counter     (ref 0)
        tRowN       (ref (count (get-records database)))
        tColN       (ref (get-num-fields database))

        tScrPane    (JScrollPane. table)
        
        tListener   (proxy [TableModelListener] []

        )
        
        model       (proxy [DefaultTableModel][@datamatrix (into-array(get-col-names database))]
        	  (isCellEditable [row col] true)                 ;All cells are editable
        )
        
        colFilter   (proxy [RowFilter][]
            (include [entry filters]
                (loop [i 0  result true]
                    (if (&lt; i (count filters))
                        (if (and (result) (not (= &quot;&quot; (nth filter i))))
                            (recur (inc i) (.startsWith (.toString (.getValue entry i)) (nth filters i)))
                            ())
                        (result)
                    )
                )
        
                ;for (int i = 0; i &lt; filters.length; i++) (
                ;    if (result &amp;&amp; !(filters[i].equals(&quot;&quot;)) ) (
                ;        String v = entry.getValue(i).toString();
                ;        result =  v.startsWith(filters[i]);
                ;    )
                ;)
            )
        )
        
        
        ;;Handlers
        hdlShowall    (proxy [ActionListener][]
                       (actionPerformed [event]
                         (dosync (alter counter inc))
                         
                         (.setText label 
                              (str (alength datamatrix)))))
                              ;(str &quot;r &quot;(.getSelectedRow table) &quot; c &quot; (.getSelectedColumn table)))))

        hdlAdd        (proxy [ActionListener][]
                       (actionPerformed [event]
                         (.setText label &quot;Adding row...&quot;)
                         ;(dosync (alter tRowN inc))
                         (.addRow model (into-array [&quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot;]))
                         ;(write-new-row testfilename
                         ;         [&quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot; &quot;&quot;] (get-field-lengths database))
                         (.setText label &quot;Row Added.&quot;)
                         (.revalidate table)))

        hdlUpdate     (proxy [ActionListener][]
                       (actionPerformed [event]
                         (if (= -1 (.getSelectedRow table))
                             (.setText label &quot;No row selected.&quot;)
                             ())))
                                
        hdlDelete     (proxy [ActionListener][]
                       (actionPerformed [event]
                         (if (= -1 (.getSelectedRow table))
                             (.setText label &quot;No row selected.&quot;)
                             (delete-record &quot;db-1x2 - copia.db&quot; (.getSelectedRow table) (get-offset database) (apply + (get-field-lengths database)))))) 
                                
        hdlFind     (proxy [ActionListener][]
                       (actionPerformed [event]
                         (println (.getText searchField))
                         (print (find-data  (.getText searchField) &quot;location&quot; (get-records database)))
                         ;(.setRowFilter sorter (RowFilter/regexFilter &quot;j[a-z]*&quot; (vec 0)))
                         (.setText label 
                                (get (nth (get-records database) (rem @counter (get-num-fields database))) :rate) )))]
                                
    ;;;;;;;;;;;;; END LET
        
;;;;;;;FRAME
    (.setDefaultCloseOperation frame JFrame/EXIT_ON_CLOSE)
    (.setLayout frame (new BorderLayout))
    
;;;;;;;PANEL
    (.setLayout         hPanel (new FlowLayout))
    ;(.setAutoResizeMode table JTable/AUTO_RESIZE_OFF)
    
    (.setLayout         fPanel (new FlowLayout))
    (.setPreferredSize  fPanel (Dimension. (+ 20 btnSX) (+ 20 (* 3 btnSY))))
    
    (.setLayout         bPanel (new FlowLayout))
    (.setPreferredSize  bPanel (Dimension. (+ 20 btnSX) (- tableSY (+ 20(* btnSY 3)))))
    
    (.setLayout         abPanel (new FlowLayout))
    (.setPreferredSize  abPanel (Dimension. (+ 20 btnSX) tableSY))
    
    ;(.setBackground     hPanel  (Color/yellow))
    ;(.setBackground     fPanel  (Color/cyan))
    ;(.setBackground     bPanel  (Color/magenta))
    ;(.setBackground     abPanel (Color/black))
    
    
;;;;;;;TABLE
    (.setModel table model)
    ;(.setRowSorter table colFilter)
    (.setPreferredSize table (Dimension. tableSX tableSY))
    (.setPreferredScrollableViewportSize table (Dimension. tableSX tableSY))
    (.setFillsViewportHeight table true)
    (.setPreferredSize tScrPane (Dimension. tableSX tableSY))
    (.setAutoCreateRowSorter table true)
    
;;;;;;;BUTTON
    (.setPreferredSize btnShowall   (Dimension. btnSX btnSY))
    (.setPreferredSize btnAdd       (Dimension. btnSX btnSY))
    (.setPreferredSize btnUpdate    (Dimension. btnSX btnSY))
    (.setPreferredSize btnDelete    (Dimension. btnSX btnSY))
    (.setPreferredSize btnFind      (Dimension. btnSX btnSY))

      ;;enable
    ;(.setEnabled btnAdd false)
    
    
;;;;;;;TEXTFIELD
    (.setPreferredSize searchField  (Dimension. btnSX btnSY))
    
;;;;;;;COMBOBOX
    (.setPreferredSize searchBox    (Dimension. btnSX btnSY))
    
;;;;;;;LABEL
    (.setPreferredSize label        (Dimension. windowSX 25))
    
;;;;;;;ADDS
    ;(.add hPanel image BorderLayout/CENTER)
    ;(.add hPanel tScrPane)
    ;(.add hPanel BorderLayout/SOUTH table)
    
    (.add fPanel BorderLayout/NORTH searchField)
    (.add fPanel BorderLayout/CENTER searchBox)
    (.add fPanel BorderLayout/SOUTH btnFind)
    
    (.add bPanel btnShowall)
    (.add bPanel btnAdd)
    (.add bPanel btnUpdate)
    (.add bPanel btnDelete)
    
    (.add abPanel BorderLayout/NORTH fPanel)
    (.add abPanel BorderLayout/SOUTH bPanel)
    
    ;(.add frame BorderLayout/NORTH hPanel)
    (.add frame BorderLayout/CENTER tScrPane)
    (.add frame BorderLayout/EAST abPanel)
    (.add frame BorderLayout/PAGE_END label)
    
    ;;;ACTION LISTENERS
    (.addActionListener btnShowall hdlShowall)
    (.addActionListener btnAdd hdlAdd)
    (.addActionListener btnUpdate hdlUpdate)
    (.addActionListener btnDelete hdlDelete)
    (.addActionListener btnFind hdlFind)

    ;(.addTableModelListener model tListener)
    
    (.pack frame)
    (.setVisible frame true)
    (.setSize frame windowSX windowSY)
    
    
    
    
  )
)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-records-to-array"/><dl class="library-member-table"><dt class="library-member-name">records-to-array</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([records])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Transforms record dictionary into a 2d array</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-records-to-array&apos;)" id="linkto-membersource-interface-records-to-array">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-records-to-array"><pre>(defn records-to-array
  &quot;Transforms record dictionary into a 2d array&quot;
  [records]
  (fliplr (to-array-2d records))
;  (let [array []]
;    (for [tuple records]
;      
;      (print (loop [filteredrow []   ituple tuple]
;        (if (empty? ituple)
; 
; (filteredrow)
;          (recur (conj filteredrow (str(first ituple)))(rest ituple))
;        )
;      ))
;      
;    )
;  )
)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-interface-table"/><dl class="library-member-table"><dt class="library-member-name">table</dt><dd><div class="library-member-info"><span class="library-member-type">var</span> <span class="library-member-arglists"></span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-interface-table&apos;)" id="linkto-membersource-interface-table">Show Source</a> ]</div><div class="library-member-source" id="membersource-interface-table"><pre>(def table          (JTable. ))</pre></div></div></dd></dl></li></ol></div></div></body></html>